package swingApps;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import javax.swing.Timer;

public class MyCirclesGame {
	int rx=1024,ry=768;
	Showable f;
	MyFigure []  a = new MyFigure[5];
	MyFigureMoveLogic l = new MyFigureMoveLogic(rx,ry);
	Timer timer = new Timer(50
			, new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) {
			for (MyFigure i : a){
				l.moveFigure(i,a);
				paint();
				f.show(im);
			}
		}
	});
	Image im = new BufferedImage(rx, ry,1);
	Graphics g = im.getGraphics();
	private MyCirclesGame(){
		for (int i = 0;i<a.length;i++){
			a[i]= new MyFigure((int) (Math.random()*(rx-100)),(int) (Math.random()*(ry-100)),(int) (Math.random()*100),(int) (Math.random()*100));
			a[i].setVector((int) (Math.random()*10),(int) (Math.random()*10));
			a[i].id=i;
		}
	}
	public MyCirclesGame(Showable f){
		this();
		this.f=f;
	}
	void paint(){
		g.setColor(new Color(0,255,255,255));
		g.fillRect(0, 0, rx, ry);
		for (MyFigure i : a){
			i.h=i.w;
			g.setColor(i.c);
			g.fillOval(i.x,i.y,i.w,i.h);
		}
	}
	public void start(){
		timer.start();
	}
}
